<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2018/11/14
  Time: 9:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <!-- 123 -->
    <link href="${pageContext.request.contextPath}/statics/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/statics/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/statics/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${pageContext.request.contextPath}/statics/bootstrapvalidator/bootstrapValidator.min.js"></script>

    <script>
        function searcha(){
            var opts=$("#usertb").bootstrapTable("getOptions");
            var limit=opts.pageSize;
            var offset=(opts.pageNumber-1)* limit
            var username=$("#username").val();
            $.post("${pageContext.request.contextPath}/huiyuanleixing/fenye1",{'username':username,'limit':limit,'offset':offset},function (data) {
                //重新绑定表格数据
                $("#usertb").bootstrapTable('load',data) ;
            });

        }

        $(function () {
            $('#fm').bootstrapValidator({
                message: '',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    huiyuanleixing_Name : {
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '类别名称不能为空！'
                            }
                        }
                    },
                    fuwu_Zheko: {
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '服务折扣不能为空！'
                            }
                        }
                    },
                    shangpin_Zheko: {
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '商品折扣不能为空！'
                            }
                        }
                    },
                    taocan_Zheko: {
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '套餐折扣不能为空！'
                            }
                        }
                    },
                    kaiKaChoZhi: {
                        message: '',
                        validators: {
                            notEmpty: {
                                message: '充值金额不能为空！'
                            }
                        }
                    }
                }
            });

            $("#usertb").bootstrapTable({
                url:'${pageContext.request.contextPath}/huiyuanleixing/fenye1',
                //设置每页多条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:300,
                pageNumber:1,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                queryParams:function(params){
                    var temp= {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit:params.limit,  //页面大小
                        offset:params.offset,  //页码
                        username:$("#username").val()
                    }
                    return temp;
                },
                columns:[
                    {
                        field:'huiyuanleixing_Name',
                        title:'类别名称'
                    },
                    {
                        field:'fuwu_Zheko',
                        title:'服务折扣'
                    },
                    {
                        field:'shangpin_Zheko',
                        title:'商品折扣'
                    },
                    {
                        field:'taocan_Zheko',
                        title:'套餐折扣'
                    },
                    {
                        field:'kaiKaChoZhi',
                        title:'充值金额'
                    },
                    {
                        field:'beizhu',
                        title:'备注'
                    },
                    {
                        title:'操作',
                        formatter:function (value,row,index) {
                            return "<button class='btn  btn-primary' onclick='javascript:xgai("+row.huiyuanleixing_Id+")'>修改</button> &nbsp;"+
                                    "<button class='btn  btn-primary' onclick='javascript:sc("+row.huiyuanleixing_Id+")'>删除</button>"
                        }
                    },
                ]
            });
        });

        //添加
        function add() {
                $("#Div3").modal('show');
        }
        function  dotianjia() {
            var huiyuanleixing_Name=$("[name=huiyuanleixing_Name]").val();
            var fuwu_Zheko=$("[name=fuwu_Zheko]").val();
            var shangpin_Zheko=$("[name=shangpin_Zheko]").val();
            var taocan_Zheko=$("[name=taocan_Zheko]").val();
            var kaiKaChoZhi=$("[name=kaiKaChoZhi]").val();
            var beizhu=$("[name=beizhu]").val();
            $.post('${pageContext.request.contextPath}/huiyuanleixing/tianjia1',{'huiyuanleixing_Name':huiyuanleixing_Name,'fuwu_Zheko':fuwu_Zheko,'shangpin_Zheko':shangpin_Zheko,'taocan_Zheko':taocan_Zheko,'kaiKaChoZhi':kaiKaChoZhi,'beizhu':beizhu},function (data) {
                if(data!=null){
                    searcha();
                    $("#Div3").modal('hide');
                }else {
                    alert("增加失败");
                }
            })
        }

        //删除
        var huiyuanleixing_Id;
        function sc(huiyuanleixing_Ids) {
            huiyuanleixing_Id=huiyuanleixing_Ids;
            $("#sc").modal('show');
        }
        function  dodelete() {
            $.post('${pageContext.request.contextPath}/huiyuanleixing/sc1',{huiyuanleixing_Id:huiyuanleixing_Id},function (data) {
                if (data!=null){
                    searcha();
                    $("#sc").modal('hide');
                }
            })
            searcha();
        }

        //修改
        var huiyuanleixing_Id=0;
        function xgai(id) {
            huiyuanleixing_Id=id;
            $("#Div4").modal('show');
            $.post('${pageContext.request.contextPath}/huiyuanleixing/xgaiid',{huiyuanleixing_Id:huiyuanleixing_Id},function (data) {
                //给表单赋值
                $("[name=huiyuanleixing_Nameg]").val(data.huiyuanleixing_Name);
                $("[name=fuwu_Zhekog]").val(data.fuwu_Zheko);
                $("[name=shangpin_Zhekog]").val(data.shangpin_Zheko);
                $("[name=taocan_Zhekog]").val(data.taocan_Zheko);
                $("[name=kaiKaChoZhig]").val(data.kaiKaChoZhi);
                $("[name=beizhug]").val(data.beizhu);
            })
        };
        function doupd() {
            var huiyuanleixing_Nameg=$("[name=huiyuanleixing_Nameg]").val();
            var fuwu_Zhekog=$("[name=fuwu_Zhekog]").val();
            var shangpin_Zhekog=$("[name=shangpin_Zhekog]").val();
            var taocan_Zhekog=$("[name=taocan_Zhekog]").val();
            var kaiKaChoZhig=$("[name=kaiKaChoZhig]").val();
            var beizhug=$("[name=beizhug]").val();
            $.post('${pageContext.request.contextPath}/huiyuanleixing/xgai1',
                {huiyuanleixing_Id:huiyuanleixing_Id,huiyuanleixing_Name:huiyuanleixing_Nameg,fuwu_Zheko:fuwu_Zhekog,shangpin_Zheko:shangpin_Zhekog,taocan_Zheko:taocan_Zhekog,kaiKaChoZhi:kaiKaChoZhig,beizhu:beizhug},function (data) {
                if(data!=null){
                    searcha();
                    $("#Div4").modal('hide');
                }else {
                    alert("修改失败");
                }
            })
        }



    </script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-6">
                <button onclick="add()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;增加</button>
            </div>
            <div class="col-sm-6">
                <form  class="form-inline pull-right">
                    <input id="username" type="text" placeholder="类别名称 " class="form-control">
                    <button class="btn btn-primary" onclick="searcha()" type="button"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;搜索</button>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="usertb"></table>
            </div>
        </div>

    </div>
</div>

<!--增加模态框-->
<div class="modal fade" id="Div3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">增加客户信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post"  id="fm" >
                    <div class="form-group">
                        <label for="titile" class="col-sm-2 control-label">类别名称:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="huiyuanleixing_Name" class="form-control" id="title1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">服务折扣:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="fuwu_Zheko" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="0.1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">商品折扣:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="shangpin_Zheko" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="0.1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">套餐折扣:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="taocan_Zheko"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="0.1">
                        </div>
                    </div>

                    <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">充值金额:</label>
                    <div class="col-sm-10">
                        <input  type="text" name="kaiKaChoZhi"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="0">
                    </div>
                </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">备注:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="beizhu"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt;>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" onclick="dotianjia()">增加</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!---删除模态框-->
<div class="modal fade" id="sc">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modelTitleId">提示信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12" id="addrole" style="height: 100px">
                        <p>确认删除客户信息吗？</p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary"onclick="dodelete()">删除</button>
            </div>
        </div>
    </div>
</div>

<!--修改模态框-->
<div class="modal fade" id="Div4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">修改客户信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" >
                    <div class="form-group">
                        <label for="titile" class="col-sm-2 control-label">类别名称:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="huiyuanleixing_Nameg" class="form-control" id="title1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">服务折扣:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="fuwu_Zhekog" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt;>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">商品折扣:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="shangpin_Zhekog" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; >
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">套餐折扣:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="taocan_Zhekog"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt;>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">充值金额:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="kaiKaChoZhig"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; >
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">备注:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="beizhug"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt;>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary"  onclick="doupd()">修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>
